#include "ScatterChart.h"
#include "../../common/utility.h"
#include <QMessageBox>
#include "../../gui/MainWindow/MainWindow.h"
namespace LightChart
{
ScatterChart::ScatterChart(QWidget* parent) : BasicXYchart(), BasicXYchartGUI(parent)
{
}
void ScatterChart::showOptions()
{
    show();
    try
    {
        title = lineEditTitle->text().toStdString();
        bgColor = get_color();
        if(!lineEditWidth->text().isEmpty())
        {
            double tmp = QStringToDouble(lineEditWidth->text());
            if(tmp < 100 || tmp > 1920) throw std::runtime_error("Wrong width specified. Width must be in [100 : 1920]");
            else windowWidth = tmp;
        }
        if(!lineEditHeight->text().isEmpty())
        {
            double tmp = QStringToDouble(lineEditHeight->text());
            if(tmp < 50 || tmp > 1080) throw std::runtime_error("Wrong height specified. Height must be in [50 : 1080]");
            else windowHeight = tmp;
        }
	static_cast<MainWindow*>(this->parentWidget())->RefreshAll();
    }
    catch(const std::runtime_error& e)
    {
        QMessageBox::critical(this,"Input data corrupted.",e.what());
    }
}
void ScatterChart::draw()
{
    PlotWindow* plotWindow = new PlotWindow(parentWidget());
    QwtBasicXYchart adapter(*this);
    adapter.preparePlot(plotWindow->get_plot(), QwtBasicXYchart::SCATTER_CHART);
    plotWindow->show();
}
}

